package date0703pm;

import java.sql.PreparedStatement;
import java.sql.SQLException;

import cn.edu.ecut.util.DatabaseType;
import cn.edu.ecut.util.JdbcHelper;

/**
 * 可以从 SQLException 中获取到的数据: message 、errorCode 、SQLState
 */
public class JdbcTest17 {

	public static void main(String[] args) {
		
		JdbcHelper h = JdbcHelper.getInstance( DatabaseType.ORACLE );
		// MySQL : 
		// CREATE  TABLE  t_users  (  id  INT(10)  auto_increment , name  VARCHAR(150) , gender  CHAR(3) , birthdate  DATE , PRIMARY KEY ( id ) ) ; 
		// Oracle:
		// CREATE  TABLE  t_users  (  id  NUMBER(10)  , name  VARCHAR2(150) , gender  CHAR(3) , birthdate  DATE , PRIMARY KEY ( id ) ) ; 
		// INSERT  INTO  t_users ( name , gender , birthdate , id ) VALUES ( '张三丰' , '男' , to_date('1912-10-10' , 'yyyy-mm-dd' ) , 1 ) ;
		PreparedStatement ps = h.prepare( "INSERT INTO t_users( name , id ) VALUES ( ? , ? )" );
		
		try {
			// 为 参数占位符 设置 参数值
			ps.setString( 1 ,  "欧阳锋" );// SQLException
			ps.setInt( 2 ,  1 ); // SQLException
			
			// "执行"SQL
			int count = ps.executeUpdate(); // SQLException
			System.out.println( "count : " + count );
		} catch ( SQLException e ) {
			System.out.println( "message : " + e.getMessage() );
			System.out.println( "error code : " + e.getErrorCode() );
			System.out.println( "SQL state : " + e.getSQLState() );
		}
		
		h.close( ps );
		h.release();

	}

}
